package io.sunny.platform.ai.deepseek.sql.controller;

import io.sunny.platform.ai.deepseek.sql.result.QueryResult;
import io.sunny.platform.ai.deepseek.sql.service.NaturalLanguageQueryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @Author SUNNY
 * @Date 2025/11/6 17:08
 * @PackageName: io.sunny.platform.ai.deepseek.sql.controller
 * @Description: 统一API接口
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/query")
@Validated
public class NaturalLanguageQueryController {

    private final NaturalLanguageQueryService queryService;

    public NaturalLanguageQueryController(NaturalLanguageQueryService queryService) {
        this.queryService = queryService;
    }

    @Operation(summary = "自然语言数据查询")
    @GetMapping("/narutal")
    public ResponseEntity<QueryResult> queryByNaturalLanguage(
            @Parameter(description = "自然语言查询语句", required = true)
            @RequestParam @NotNull String q) {
        QueryResult result = queryService.executeNaturalLanguageQuery(q);
        return ResponseEntity.ok(result);
    }

    @Operation(summary = "批量自然语言查询")
    @GetMapping("/batch")
    public ResponseEntity<List<QueryResult>> batchQuery(
            @RequestBody @Valid List<String> querys) {
        List<QueryResult> results = querys.stream()
                .map(queryService::executeNaturalLanguageQuery)
                .toList();
        return ResponseEntity.ok(results);
    }
}
